#ifndef VECTOR2_HPP
#define VECTOR2_HPP

/********************************************************************
	created:	2011/01/14
	filename: 	E:\C++\Red\src\Utils\Math\Vector2.hpp
	author:		Red
	
	purpose:	2D Vector Class. Need maybe some work for a 2D Game
				use
*********************************************************************/

#include "Mathlib.hpp"

namespace red {
	/// 2D Vector Template Class
	template<typename T>
	class Vector2{
	public:
		Vector2(T x = 0, T y = 0);

		Vector2(const Vector2<T> &V);

		/// Sets vector components
		void Set(T x, T y);

		/// Returns the vector components in an array
		void XY(T pTab[]) const;

		/// Returns the vector length
		T Length() const;

		/// Returns the Squared Length (intern use for Length())
		T LengthSq() const;

		/// Normalize the vector
		void Normalize();

		/// Returns the negate of the vector
		Vector2<T> operator- () const;

		// Binary operators
			Vector2<T> operator+ (const Vector2<T> &V) const;
			Vector2<T> operator- (const Vector2<T> &V) const;

			Vector2<T>& operator+= (const Vector2<T> &V);
			Vector2<T>& operator -= (const Vector2<T> &V);

			Vector2<T> operator*(T t) const;
			Vector2<T> operator/(T t) const;

			Vector2<T>& operator*= (T t);
			Vector2<T>& operator /= (T t);

		// Comparison operators
			bool operator==(const Vector2<T> &V) const;
			bool operator!=(const Vector2<T> &V) const;

		/// Affectation operator
		void operator=(const Vector2<T> &V);

		/// Returns a pointer on x
		operator T*();

		/// Common Zero Vector
		static const Vector2 ZERO;

		// Data
		T x;
		T y;
	};


	/// Result of multiplication between a vector and a T
	//template<class T> Vector2<T> operator* (const Vector2<T> &V, T t);

	/// Result of division between a vector and a T
	template<class T> Vector2<T> operator/ (const Vector2<T> &V, T t);

	/// Result of multiplication between a T and a vector
	template<class T> Vector2<T> operator* (T t, const Vector2<T> &V);

	/// Dot product between two vector2
	template<class T> T Dot(const Vector2<T> &U, const Vector2<T> &V);

	// Stream ops
	template<class T> std::istream& operator >>(std::istream& iss, Vector2<T> &V);
	template<class T> std::ostream& operator <<(std::ostream& oss, const Vector2<T> &V);

	// Typedef
	typedef Vector2<s32> Vector2I;
	typedef Vector2<f32> Vector2F;

	#include "Vector2.inl"
}
#endif
